package Login;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import cliente.ClienteDAOImplements;
import Login.Login;
import Login.LoginDaoImplements;



public class LoginDaoImplements implements LoginDao {

	
	private static final Logger logger = Logger
			.getLogger(ClienteDAOImplements.class.getName());

	private Session session;

	public void setSession(Session session) {
		this.session = session;
	}
		
	@Override
	public void salvar(Login login) {
	
		try {
			this.session.save(login);

		} catch (HibernateException e) {
			logger.error("Nao foi possivel salvar o objeto Login na base de dados.: "
					+ e.getMessage());
		}

		
	}

	@Override
	public void alterar(Login login) {
	

		try {
			this.session.update(login);

		} catch (HibernateException e) {
			logger.error("Nao foi possivel alterar o objeto Login na base de dados.: "
					+ e.getMessage());
		}					
	
	}

	@Override
	public void excluir(Login login) {
		
		try {
			this.session.delete(login);

		} catch (HibernateException e) {
			logger.error("Nao foi possivel excluir o objeto Login na base de dados.: "
					+ e.getMessage());
		}
		
	}

	@Override
	public List<Login> buscarPorID(int Id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Login> buscarGeralLogin() {
		// TODO Auto-generated method stub
		return this.session.createCriteria(Login.class).list();
	}
	
public List<Login> buscarGeral() {
		
		String hql = "select c from Login c";
		org.hibernate.Query query = this.session.createQuery(hql);
		return (List<Login>) query.list();

	}

	}
